﻿using System.Collections.Generic;
using System.Linq;

namespace BotModels
{
    public class LibraryRepository : BotModels.ILibraryRepository
    {
        LibraryDataContext context;

        public LibraryRepository()
        {
            context = new LibraryDataContext();
        }

        public IEnumerable<Bot> GetAllBots()
        {
            return context.Bots.ToList();
        }

        public bool AddBot(Bot bot)
        {
            try
            {
                context.Bots.InsertOnSubmit(bot);
                context.SubmitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool DeleteBot(Bot bot)
        {
            context.Bots.DeleteOnSubmit(bot);

            try
            {
                context.SubmitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool UpdateBot(Bot bot)
        {
            return false;
        }
    }
}
